# @Time : 2020/6/24 14:17
# @Author : Fioman 
# @Phone : 13149920693
"""
1> 元组不仅仅是不可变的列表.
2> 元组和记录.元组除了不可变之后,另外一个信息是它有记录位置的功能.
"""
import os

if __name__ == '__main__':
    # 把元组用作记录
    beijing_coordinates = (33.9425, -118.408056)
    city, year, pop, chg, area = ("Tokyo", 2003, 32450, 0.66, 8014)
    traveler_ids = [('USA', '31195855'), ('BRA', 'CE342567'), ('ESP', 'XDA205856')]

    for passport in sorted(traveler_ids):
        print("{}/{}".format(passport[0], passport[1]))

    for contry, _ in traveler_ids:
        print(contry)

    # 元组拆包
    latitude, longitude = beijing_coordinates
    print("latitude = {},longitude = {}".format(latitude, longitude))
    latitude, longitude = longitude, latitude  # 经典的调换两个变量的值
    a = divmod(20, 8)  # 20 / 8 的结果和余数.
    print("a = {}".format(a))

    t = (20, 8)
    b = divmod(*t)
    print("b = {}".format(b))

    quotient, remainder = divmod(*t)
    print("quotient,remainder".format(quotient, remainder))

    filedir, filename = os.path.split(r"D:\jianding_raw\new\2619--2020-06-23_14-03-33--w_2238--h_1968.bmp")
    print("filedir = {}, filename = {}".format(filedir, filename))

    # 使用*号来处理不确定的多余的变量是一种经典的写法了.*rest 会用一个列表来保存
    a, b, *rest = range(5)
    print("a = {},b = {},rest = {}".format(a, b, rest))
    a, b, *rest = range(3)
    print("a = {},b = {},rest = {}".format(a, b, rest))
    a, b, *rest = range(2)
    print("a = {},b = {},rest = {}".format(a, b, rest))

    a, *body, c, d = range(5)
    print("a = {},body = {},c = {},d = {}".format(a, body, c, d))
    *head, b, c, d = range(5)
    print("head = {},b = {},c = {},d = {}".format(head, b, c, d))
